package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Food;
import service.FoodManager;
import service.impl.FoodManagerImpl;
import util.JsonUtil;

public class ShowFoodListDataServlet extends HttpServlet {
    private FoodManager foodManager;
    private static final long serialVersionUID = 1L;

    public ShowFoodListDataServlet() {
        foodManager = new FoodManagerImpl();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String typeId = request.getParameter("typeId");
        String m_id = request.getParameter("m_id");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-type", "text/html;charset=UTF-8");

        List<Food> list;
        list = foodManager.find(m_id, typeId);

        PrintWriter writer = response.getWriter();
        writer.write(JsonUtil.toJsonString(list));
    }

}
